<template>
    <div class="page_edithouse">
        <common-header :title="'房屋信息编辑'">
            <span slot="overwrite-left"></span>
        </common-header>
        <div class="btn-save" @click="saveLandTransferInfo">保存</div>
        <div class="pages-main" style="height: calc( 100vh - 45px)">
            <div class="item-info">
                <div class="item-item">
                    <div class="item-item every-block-padding item-inline">
                        <span class="item-itemLabel">所在区域</span>
                        <select class="translateBlock" v-model="info.villagecode"
                                style="text-align-last: right;;width: 7.25rem;font-size:0.38rem;">
                            <option v-for="item in xnsRegionList" :value="item.code">{{item.name}}</option>
                        </select>
                    </div>
                </div>
                <div class="item-item  every-block-padding item-inline">
                    <span class="item-itemLabel">房屋类型</span>
                    <select class="translateBlock" v-model="info.housetype"
                            style="text-align-last: right;;width: 7.25rem;font-size:0.38rem;">
                        <option :value="1">自建住房</option>
                        <option :value="2">安置住房</option>
                        <option :value="3">商品住房</option>
                        <option :value="4">其他</option>
                    </select>
                </div>
                <div class="item-item">
                    <x-input title="房屋面积(亩)" type="number" v-model="info.housearea"
                             placeholder="请输入房屋面积(亩)">
                    </x-input>
                </div>
                <div v-if="info.housetype === 1">
                    <div class="item-item">
                        <datetime :min-year="1900" title="审批时间" placeholder="请选择审批时间" v-model="examinetime"></datetime>
                    </div>
                    <div class="item-item">
                        <x-input title="审批面积(亩)" type="number" v-model="info.examinearea"
                                 placeholder="请输入审批面积(亩)">
                        </x-input>
                    </div>
                    <div class="item-item">
                        <x-input title="审批编号" type="text" v-model="info.examinenumber"
                                 placeholder="请输入审批编号">
                        </x-input>
                    </div>
                </div>
                <div class="item-item">
                    <datetime  :min-year="1900" title="购/建时间" placeholder="请选择购/建时间" v-model="buildingtime"></datetime>
                </div>
                <div class="item-item  every-block-padding item-inline">
                    <span class="item-itemLabel">是否危房</span>
                    <select class="translateBlock" v-model="info.dilapidatedlevel"
                            style="text-align-last: right;;width: 7.25rem;font-size:0.38rem;">
                        <option :value="'D'">D级</option>
                        <option :value="'C'">C级</option>
                        <option :value="'B'">B级</option>
                        <option :value="'A'">A级</option>
                        <option :value="'0'">否</option>
                    </select>
                </div>

                <div v-if="info.dilapidatedlevel !== '0'">

                    <div class="item-item  every-block-padding item-inline">
                        <span class="item-itemLabel">发放改造补贴</span>
                        <select class="translateBlock" v-model="info.hadsendreformcost"
                                style="text-align-last: right;;width: 6.45rem;font-size:0.38rem;">
                            <option :value="1">是</option>
                            <option :value="0">否</option>
                        </select>
                    </div>

                    <div v-if="info.hadsendreformcost === 1">
                        <div class="item-item">
                            <x-input title="补贴金额（元）" type="number" v-model="info.reformamount"
                                     placeholder="请输入补贴金额（元）">
                            </x-input>
                        </div>

                        <div class="item-item">
                            <datetime :min-year="1900" title="发放时间" placeholder="请选择发放时间" v-model="reformsendtime"></datetime>
                        </div>
                    </div>

                    <div class="item-item  every-block-padding item-inline">
                        <span class="item-itemLabel">是否完成改造</span>
                        <select class="translateBlock" v-model="info.reformfinish"
                                style="text-align-last: right;;width: 6.45rem;font-size:0.38rem;">
                            <option :value="1">是</option>
                            <option :value="0">否</option>
                        </select>
                    </div>

                    <div class="item-item" v-if="info.reformfinish === 1">
                        <datetime :min-year="1900" title="改造时间" placeholder="请选择改造时间" v-model="reformtime"></datetime>
                    </div>

                </div>

                <div class="item-item">
                    <x-input title="备注" type="text" v-model="info.remarks"
                             placeholder="请输入备注">
                    </x-input>
                </div>

                <div class="item-item  every-block-padding item-inline">
                    <span class="item-itemLabel">是否有产权证</span>
                    <select class="translateBlock" v-model="info.propertyright"
                            style="text-align-last: right;;width: 6.45rem;font-size:0.38rem;">
                        <option :value="1">是</option>
                        <option :value="0">否</option>
                    </select>
                </div>

                <div v-if="info.propertyright === 1">
                    <div class="item-item">
                        <x-input title="产权证编号" v-model="info.certificatesnumber"
                                 placeholder="请输入产权证编号">
                        </x-input>
                    </div>

                    <div class="item-item">
                        <datetime :min-year="1900" title="取得时间" placeholder="请选择取得时间" v-model="acquisitiontime"></datetime>
                    </div>
                </div>

            </div>
        </div>
    </div>
</template>

<script>
    import resident from '../../services/resident'
    import {XInput, Selector, Datetime} from 'vux'
    import Vue from 'vue'
    import {checkNumber} from '../../utils/validate'
    export default {
        name: "edithouse",
        components: {
            XInput, Selector, Datetime
        },
        data() {
            return {
                id: this.$route.query.id,
                examinetime: this.$route.query.examinetime ? this.$route.query.examinetime : '',
                buildingtime: this.$route.query.buildingtime ? this.$route.query.buildingtime : '',
                reformsendtime: this.$route.query.reformsendtime ? this.$route.query.reformsendtime : '',
                reformtime: this.$route.query.reformtime ? this.$route.query.reformtime : '',
                acquisitiontime: this.$route.query.acquisitiontime ? this.$route.query.acquisitiontime : '',
                info: {
                    familyid: this.$route.query.familyid,
                    villagecode: this.$route.query.villagecode,
                    housetype: Number(this.$route.query.housetype) ? Number(this.$route.query.housetype) : 1,
                    housearea: this.$route.query.housearea ? this.$route.query.housearea : '',
                    examinetime: '',
                    examinearea: this.$route.query.examinearea ? this.$route.query.examinearea : '',
                    examinenumber: this.$route.query.examinenumber ? this.$route.query.examinenumber : '',
                    buildingtime: '',
                    isdilapidated: Number(this.$route.query.isdilapidated) === 0 ? 0 : 1,
                    dilapidatedlevel: this.$route.query.dilapidatedlevel  ? this.$route.query.dilapidatedlevel : '0',
                    hadsendreformcost: Number(this.$route.query.hadsendreformcost) ? 1 : 0,
                    reformamount: this.$route.query.reformamount ? this.$route.query.reformamount : '',
                    reformsendtime: '',
                    reformfinish: Number(this.$route.query.reformfinish) ? 1 : 0,
                    reformtime: '',
                    propertyright: Number(this.$route.query.propertyright) === 0 ? 0 : 1,
                    certificatesnumber: this.$route.query.certificatesnumber ? this.$route.query.certificatesnumber : '',
                    acquisitiontime: '',
                    remarks: this.$route.query.remarks ? this.$route.query.remarks : '',
                },
                xnsRegionList: [],
            }
        },

        watch: {},
        mounted() {
            this.getXnsRegionList()
        },
        methods: {

            // 获取户籍地列表
            getXnsRegionList() {
                let _param = this.$tools.invokeUAF('resident/getXnsRegionList', {})
                resident.getXnsRegionList(_param).then(res => {
                    let data = res.data.data;
                    this.xnsRegionList = data;
                })
            },

            // 保存zheng地信息
            saveLandTransferInfo() {
                if (!this.info.housearea) {
                    Vue.$vux.toast.show({
                        type: 'text',
                        text: '请输入正确的房屋面积（数字类型且最多保留两位小数）',
                        position: 'middle',
                    })
                    return;
                }else{
                    if(!checkNumber(this.info.housearea,'房屋面积')){
                        return
                    }
                }

                if (this.info.housetype === 1) {
                    if (!this.examinetime) {
                        Vue.$vux.toast.show({
                            type: 'text',
                            text: '请选择审批时间',
                            position: 'middle',
                        })
                        return;
                    }
                    let param = {
                        examinearea: '请输入正确的审批面积（数字类型且最多保留两位小数）',
                        examinenumber: '请输入审批编号',
                    }
                    for (let i in param) {
                        if (!this.info[i]) {
                            Vue.$vux.toast.show({
                                type: 'text',
                                text: param[i],
                                position: 'middle',
                            })
                            return;
                        }
                    }

                        if(!checkNumber(this.info.examinearea,'审批面积')){
                            return
                        }

                }

                if(this.info.hadsendreformcost === 1){
                    if(!this.info.reformamount){
                        Vue.$vux.toast.show({
                            type: 'text',
                            text: '请输入正确的补贴金额（数字类型且最多保留两位小数）',
                            position: 'middle',
                        })
                        return;
                    }else{
                        if(!checkNumber(this.info.reformamount,'补贴金额')){
                            return
                        }
                    }
                    if(!this.reformsendtime){
                        Vue.$vux.toast.show({
                            type: 'text',
                            text: '请输入补贴发放时间',
                            position: 'middle',
                        })
                        return;
                    }
                }


                if (!this.buildingtime) {
                    Vue.$vux.toast.show({
                        type: 'text',
                        text: '请选择购/建时间',
                        position: 'middle',
                    })
                    return;
                }

                this.info.isdilapidated = this.info.dilapidatedlevel === '0' ? 0 : 1;
                this.info.acquisitiontime = this.acquisitiontime ? this.acquisitiontime + ' ' + '00:00:00' : '';
                this.info.buildingtime = this.buildingtime ? this.buildingtime + ' ' + '00:00:00' : '';
                this.info.examinetime = this.examinetime ? this.examinetime + ' ' + '00:00:00' : '';
                this.info.reformsendtime = this.reformsendtime ? this.reformsendtime + ' ' + '00:00:00' : '';
                this.info.reformtime = this.reformtime ? this.reformtime + ' ' + '00:00:00' : '';
                if (this.id) {
                    this.info = Object.assign(this.info, {id: this.id})
                }
                let _param = this.$tools.invokeUAF('residen t/saveHouseBaseInfo', this.info)
                resident.saveHouseBaseInfo(_param).then(res => {
                })
            },
        },
    };
</script>

<style lang="less" rel="stylesheet/less" type="text/css">
    .page_edithouse {
    }

</style>
